﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BattleShipProject
{
	public class Board
	{
		public Board(int size)
		{
			Size = size;
		}

		public int Size { get; set; }

		public int[,] Cells
		{
			get
			{
				int[,] cells = new int[Size, Size];


				return cells;
			}
		}

		public List<Ship> Ships { get; set;}

		public void AddShip(Ship newShip)
		{
			if(!CheckShip(newShip))
			{
				throw new Exception("Cannot add ship. Choose another position");
			}

			Ships.Add(newShip);
		}

		private bool CheckShip(Ship newShip)
		{
			foreach (Cell sc in newShip.ShipCells)
			{
				if(sc.X < 0 || sc.X >= Size || sc.Y < 0 || sc.Y >= Size)
				{
					return false;
				}

				foreach (Ship ship in Ships)
				{
					foreach(Cell bc in ship.BlockedCells)
					{
						if(sc.X == bc.X && sc.Y == bc.Y)
						{
							return false;
						}
					}
				}
			}

			return true;
		}
	}
}
